<?php

namespace app\mobile\controller;

use app\common\controller\Frontend;
use think\Db;
use think\Request;

class Hangyezhanhui extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';

    public function index()
    {
        $banner = Db::name('banner')->where([
            'type_data' => 1,
            'bannertype_id' => 5
        ])->find();
        $this->assign('banner', $banner);

        $hangyezhanhuitype = Db::name('hangyezhanhuitype')->where([
            'show_switch' => 1,
        ])->order('weigh desc')->select();

        $today = date('Y-m-d');

        foreach ($hangyezhanhuitype as $k => $v) {
            $hangyezhanhuitype[$k]['list'] = Db::name('hangyezhanhui')->where(['hangyezhanhuitype_id' => $v['id']])
                ->orderRaw("ABS(DATEDIFF(start_date, '$today'))")
                ->select();
        }
        $all_hangyezhanhui = Db::name('hangyezhanhui')->orderRaw("ABS(DATEDIFF(start_date, '$today'))")->select();
        $this->assign('hangyezhanhuitype', $hangyezhanhuitype);
        $this->assign('all_hangyezhanhui', $all_hangyezhanhui);
        return $this->view->fetch();
    }

    public function detail(Request $request)
    {
        $id = $request->param('id/d', 0);
        $rs = Db::name('hangyezhanhui')->where(['id' => $id])->find();
        if (is_null($rs)) {
            $this->error('内容不存在');
        }
        $this->assign('rs', $rs);
        return $this->view->fetch();
    }

}
